package org.microsleep;

public class Reference {
	private final PersistentClass persistentClass;
	private final Object identifier;

	public Reference(PersistentClass persistentClass, Object identifier) {
		super();
		this.persistentClass = persistentClass;
		this.identifier = identifier;
	}

	public PersistentClass getPersistentClass() {
		return persistentClass;
	}

	public Object getIdentifier() {
		return identifier;
	}

	@Override
	public String toString() {
		return persistentClass.getMappedClass().getName() + "[" + identifier
				+ "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((identifier == null) ? 0 : identifier.hashCode());
		result = prime * result
				+ ((persistentClass == null) ? 0 : persistentClass.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Reference other = (Reference) obj;
		if (identifier == null) {
			if (other.identifier != null)
				return false;
		} else if (!identifier.equals(other.identifier))
			return false;
		if (persistentClass == null) {
			if (other.persistentClass != null)
				return false;
		} else if (!persistentClass.equals(other.persistentClass))
			return false;
		return true;
	}

}
